package com.woniuxy.course.controller;


import com.woniuxy.course.entity.ArticleRelease;
import com.woniuxy.course.entity.TeacherInfo;
import com.woniuxy.course.exception.GuliException;
import com.woniuxy.course.service.TeacherInfoService;
import com.woniuxy.course.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cyh
 * @since 2020-08-03
 */
@RestController
@RequestMapping("/teacherInfo")
public class TeacherInfoController {
    @Autowired
    private TeacherInfoService teacherInfoService;
    //通过id更新
    @RequestMapping("/updateArticleById")
    @ResponseBody
    public Integer updateTeacherInfo(TeacherInfo teacherInfo){
        System.out.println(teacherInfo);
        Integer integer = teacherInfoService.updateTeacherInfo(teacherInfo);

        return integer;
    }
    //上传附件
    @PostMapping("'upload")
    public R upload(MultipartFile file){
        String url=null;
        if(null==file){
            throw new GuliException(20001,"传送空文件");
        }else {
            url= teacherInfoService.upload(file);
        }

        if(null==url){
            return R.error().message("文件上传失败,稍后重试");
        }
        return R.ok().data("url",url).message("文件上传成功");
    }
    @RequestMapping("/findTeacherInfoById")
    @ResponseBody
    public TeacherInfo findTeacherInfoById(Long id){
        System.out.println("查询的id为"+id);
        TeacherInfo articleById = teacherInfoService.findTeacherInfoById(id);
        return articleById;
    }
}

